<?php

class userTag{

	/**
	 *  调用广告
	 * @access    public
	 * @return    array
	 */

	public static function ad($abc){
		$yuming_id = $GLOBALS['W']['id'];
		$ad = db::find("select content from ads where abc ='$abc' AND (yuming_id=0 or yuming_id='$yuming_id') AND status=1 order by yuming_id desc");
		
		$html = $ad['content'];
		return  $html;
	}

	/**
	 *  友情链接
	 * @access    public
	 * @return    array
	 */

	public static function flink($num){
		$yuming_id = $GLOBALS['W']['id'];
		$flink=db::select("select * from flink where status=1 and yuming_id=0 OR yuming_id='$yuming_id' limit $num");
		return  $flink;
	}

	/**
	 *  页面标签
	 * @access    public
	 * @return    array
	 */

	public static function tags($num=10){
		$yuming_id = $GLOBALS['W']['id'];
		$tags=db::select("select * from tagslist_{$yuming_id} where yuming_id='$yuming_id' limit $num");
		return  $tags;
	}
    
    public static function arctags($id) {
        $yuming_id = $GLOBALS['W']['id'];
        $res = db::select("select t.id,t.tagsname from tagindex_{$yuming_id} as i, tagslist_{$yuming_id} as t where i.tagid=t.id and i.aid='$id'");
		return  $res;
    }

    public static function volist($request_string) {
		return self::arclist($request_string, true);
	}

	public static function arclist($request_string, $autosp = false) {
		parse_str($request_string, $arr);
		if ($autosp) {
			$arr['tagname'] = 'list';
		}

		$uri_info = parse_url($_SERVER['REQUEST_URI']);
		$rest_uri = trim($uri_info['path'], '/');

		$url = $rest_uri;
		if(empty($url)||preg_match('#news#', $url)){
			
		}elseif(preg_match('#hot#', $url)){
			$arr['orderby'] = 'click';
			$arr['orderway'] = 'desc';
		}elseif(preg_match('#tu#', $url)){
			$arr['flag'] = empty($arr['flag']) ? 'p' : $arr['flag'].',p';
		}

		$list = get_arclist($arr, 'list');
		
		foreach ($list as $key => $val) {
			$content = ymcms::article_read($GLOBALS['W']['id'], $val['id']);
			
			preg_match_all('/<img.+?src=["\']*([^"\'\s\>]+)/i', $content, $mt);
				
			$imglist = array_filter($mt[1]);
			if (count($imglist)>4) {
				$imglist = array_slice($imglist, 0, 5);
				foreach ($imglist as $k => $v) {
					if (strpos($v, 'http')===false) {
						$imglist[$k] = preg_replace("#(\.[^\.]*)$#", '_small$1', $v);
					}
					
				}
			} else {
				$imglist = false;
			}
			
			$val['imglist'] = $imglist;

			$list[$key] = $val;
		}
		return $list;
	}
        

	public static function pagelink($request_string = "") {
		parse_str($request_string, $arr);
		return get_pagelist($arr);
	}
        
	// php5.3+
	public static function __callStatic($func, $args)
    {
        switch ($func)
        {
			case 'test':
				trigger_error("您正在调用测试标签", E_USER_ERROR);die ();
            break;
            default:
				trigger_error("您正在调用一个不存在的标签 ".__CLASS__."::$func()", E_USER_ERROR);die ();
			break;
        }
    }
    
    // ["get"] => "pre"
    //["get"] => "next"
    public static function prenext($string='next',$article_content) {
        $param_arr['get'] = $string;
        $__prenext = get_prenext($article_content, $param_arr);
        return $__prenext;
    }

}

